package com.wangyadong.hobby.thread.lesson2;

import com.wangyadong.hobby.thread.lesson2.CharacterListener;
import com.wangyadong.hobby.thread.lesson2.CharacterSource;
import com.wangyadong.hobby.thread.lesson2.example2.RandomCharacterGenerator;

import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.IntStream;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2019/8/2011:31
 **/
public class Main {


    private static Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        System.out.println(Long.MIN_VALUE);
        int teb = 10;
        System.out.println("start...");
        CharacterEventHandler handler = new CharacterEventHandler();
        handler.addCharacterListener(new CharacterListener() {
            @Override
            public void newCharacter(CharacterEvent ce) {
                System.out.println("内部-->" + ce.character);
            }
        });

        handler.fireNewCharacter(new RandomCharacterGenerator(), 2);
        handler.fireNewCharacter(new RandomCharacterGenerator(), 12);
        System.out.println("ending ...");
//        System.out.println(194143 / 2000);
//        int total = 194143;
//        int startIndex = 0;
//        int endIndex = 2000;
//        int remainder = total / endIndex;
//        for (int i = 0; i < remainder; i++) {
//            startIndex = endIndex;
//            endIndex = endIndex + 2000;
//            if (endIndex > total) {
//                endIndex = total;
//            }
//            System.out.println(startIndex + " --->  " + endIndex);
//        }

//        IntStream.range(0, 100).forEach(i -> {
//            new Thread(() -> {
//                try {
//                    testsync("0", "0");
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }).start();
//        });
//        Thread.sleep(10000);
//        testsync("1", "1");
//        Thread.sleep(5000);
//        testsync("2", "2");
//        testsync("0", "100");
//
//
//    }
//
//    static ConcurrentHashMap<String, Object> locks = new ConcurrentHashMap<>();
//
//    public static void testsync(String key, String message) throws InterruptedException {
//
//        locks.putIfAbsent(key, new Object());
//        synchronized (locks.get(key)) {
//            Thread.sleep(1000);
//            System.out.println("  ");
//            System.out.println(Thread.currentThread().getId() + " call  and key is " + key + " value hashcode is "
//                    + locks.get(key).hashCode() + " message " + message);
//        }
    }
}
